package com.cqgc.mapper;

import com.cqgc.pojo.dto.UserDTO.*;
import com.cqgc.pojo.entity.User;
import com.cqgc.pojo.vo.UserLikeVO;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {


    @Select("select *from user where account=#{account} and password=#{password} and state = 1")
    User login(UserLoginDTO user);

    @Select("select *from user where account=#{account} and phone=#{phone} ")
    User findByUsernameAndPhoneNumber(UserForgetDTO userForgetDTO);

    @Update("update user set password = #{password} where account=#{account} and phone=#{phone}")
    int update(User user);

    @Select("select uid from user where phone = #{phone}")
    int findUidByAccount(String phone);


    @Select("select * from user where account = #{account}")
    User findAccount(String account);

//    @Select("select * from user")
    Page<UserLikeVO> list(UserPageQueryDTO userMapper);

    @Select("select password from user where uid = #{uid}")
    String findPwdByid(Integer uid);

    @Update("update user set password = #{newPwd},update_time = now() where uid = #{uid}")
    void updatePwd(String newPwd, Integer uid);

    //    @Update("update user set nick_name = #{nickName},phone = #{phone}, update_time = now() where uid = #{uid}")
    int update1(User user);

    @Select("select * from user where phone = #{phone}")
    UserRegisterDTO findUserByPhone(String phone);

    int register(User user);

    @Select("select * from user where uid = #{id}")
    List<User> findById(Integer id);

    //查询用户的身份
    @Select("select name from role where rid  in (select rid from role_user where uid = (select uid from user where uid = #{uid}))")
    List<String> getUserRoleInfoMapper(@Param("uid") int uid);

    //查询用户的权限
    List<String> getUserPermissionInfoMapper(@Param("roles") List<String> roles);

    @Select("select * from user where uid= #{uid}")
    User findByUser(int uid);

//    int addUser(AddUserDTO addUserDTO);

    List<User> findUserByRole(int rid);

    int findRoleByUid(int uid);

//    @Update("update avatar set user_pic = #{avatarUrl} and uid = #{uid}")
    void updateAvatar(String avatarUrl, Integer uid);

    @Select("select user_pic from avatar where uid = #{uid}")
    String getImgUrl(Integer uid);

    @Insert("insert into avatar(uid,user_pic,create_time,update_time) values (#{uid},'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png',now(),now())")
    void addAvatar(int uid);

    int addUser(User user);

    Page<UserLikeVO> findUserByIf(LikeUserDTO likeUserDTO);

    @Delete("delete from user where uid = #{uid}")
    int delete(int uid);

    @Update("update user set password = #{newPwd} where uid = #{uid}")
    int resetPwd(String newPwd,Integer uid);
}
